-- plots a rectangle
Canvas.rect = function(self, l, t, r, b)
  local w = math.abs(r - l)
  local h = math.abs(b - t)
  local x = l + w/2
  local y = t + h/2
  self:move_to(x, y)
  self:rectangle(w, h)
end
--[[
Canvas.write_align = function(self, font, sz, x, y, width, align)
  local out = font:clamp(sz, width, "...")
  local w = font:get_width(out)
  local ox = 0
  if align == 'center' then
    ox = width/2 - w/2
  elseif align == 'right' then
    ox = width - w
  end
  self:move_to(x + ox, y)
  self:write(out)
end
]]
--[[
-- plots a beveled rectangle
Canvas.brect = function(self, l, t, r, b, radius)
  self:move_to(l - radius, t)
  self:line_to(l, t - radius - 1)
  self:line_to(r, t - radius - 1)
  self:line_to(r + radius, t)
  self:line_to(r + radius, b)
  self:line_to(r, b + radius)
  self:line_to(l, b + radius)
  self:line_to(l - radius, b)
  self:close_path()
end
]]
--[[
-- plots a rounded rectangle
Canvas.rrect = function(self, l, t, r, b, radius)
  local w = math.abs(r - l)
  local h = math.abs(b - t)
  local hw, hh = w/2, h/2
  self:rectangle(w, h - radius * 2)
  self:rectangle(w - radius * 2, h)
  self:rel_move_to(-hw + radius, hh - radius)
  self:circle(r)
  self:rel_move_to(w - radius * 2, 0)
  self:circle(r)
  self:rel_move_to(0, -h + radius * 2)
  self:circle(r)
  self:rel_move_to(-w + radius * 2, 0)
  self:circle(r)
  self:rel_move_to(hw - radius, hh - radius)
end
]]